package com.ruoyi.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.admin.domain.Bed;
import com.ruoyi.admin.domain.vo.BedVO;
import com.ruoyi.admin.service.IBedService;
import com.ruoyi.admin.service.IHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 共享床位信息Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/bed")
public class BedController extends BaseController
{
    @Autowired
    private IBedService bedService;

    @Autowired
    private IHospitalService hospitalService;

    /**
     * 查询共享床位信息列表
     */
    @RequiresPermissions("admin:bed:list")
    @GetMapping("list")
    public TableDataInfo list(Bed bed){
        startPage();
        List<BedVO> list = bedService.selectAllByPage(bed);
        return getDataTable(list);
    }
    /**
     * 导出共享床位信息列表
     */
    @RequiresPermissions("admin:bed:export")
    @Log(title = "共享床位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bed bed)
    {
        List<Bed> list = bedService.selectBedList(bed);
        ExcelUtil<Bed> util = new ExcelUtil<Bed>(Bed.class);
        util.exportExcel(response, list, "共享床位信息数据");
    }

    /**
     * 获取共享床位信息详细信息1111
     */
    @RequiresPermissions("admin:bed:query")
    @GetMapping(value = { "/", "/{bedId}" })
    public AjaxResult getInfo(@PathVariable(value = "bedId", required = false) Long bedId)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("factoryPerson",bedService.selectAllFactoryPerson());
        System.out.println(bedService.selectAllFactoryPerson());
        ajax.put("hospitals",hospitalService.selectAllHospital1());
        ajax.put("bed",bedService.selectBedByBedId1(bedId));
        return ajax;
    }
    /**
     * 新增共享床位信息
     */
    @RequiresPermissions("admin:bed:add")
    @Log(title = "共享床位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bed bed)
    {
        return AjaxResult.success(bedService.insertBed(bed));
    }

    /**
     * 修改共享床位信息
     */
    @RequiresPermissions("admin:bed:edit")
    @Log(title = "共享床位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bed bed)
    {
        return toAjax(bedService.updateBed(bed));
    }

    /**
     * 删除共享床位信息
     */
    @RequiresPermissions("admin:bed:remove")
    @Log(title = "共享床位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bedIds}")
    public AjaxResult remove(@PathVariable Long[] bedIds)
    {
        return toAjax(bedService.deleteBedByBedIds(bedIds));
    }
}